import csv

# 读取 CSV 文件
def read_csv(file_name):
    data = []
    with open(file_name, 'r', newline='', ) as file:
        reader = csv.DictReader(file)
        for row in reader:
            data.append(row)
    return data

# 根据条件筛选结果
def filter_data(data, conditions):
    filtered_data = data
    for condition in conditions:
        filtered_data = [row for row in filtered_data if row.get(condition[0], '') == condition[1]]
    return filtered_data

# 主程序
def main():
    # 读取 CSV 文件
    file_name = "xiaofei.csv"
    data = read_csv(file_name)

    # 获取用户输入的条件
    conditions = []
    while True:
        province = input("请输入省份：")
        item = input("请输入需要查找的项目：")
        conditions.append((province, item))
        if input("是否继续输入？(输入'y'继续，其他键退出)") != 'y':
            break

    # 根据条件筛选结果并显示
    filtered_data = filter_data(data, conditions)
    if filtered_data:
        print("查询结果：")
        for row in filtered_data:
            print(row)
    else:
        print("未找到符合条件的记录。")

if __name__ == "__main__":
    main()
